package pl.donajski.worldBrowser.primefaces;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;
import pl.donajski.worldBrowser.entities.Country;

public class CountryModel extends ListDataModel<Country> implements SelectableDataModel<Country>, Serializable {

	private static final long serialVersionUID = 1L;
	
	public CountryModel(List<Country> countries) {
		super(countries);
	}
	
	public Country getRowData(String code) {
		for(Country c : this) {
			if(c.getCode().equals(code))
				return c;
		}
		return null;
	}

	public Object getRowKey(Country c) {
		return c.getName();
	}
}
